<template>
  <div class="g-container">
    <div>
      <span class="title">数据库数量</span>
      <div class="content scroll"  >
        <div
          v-for="(item, index) in databasesNum"
          :key="index"
          @click="handleDialog(item, index)"
        >
          <p class="tag">
            <span>{{ item.value || 0 }}</span>
          </p>
          <p class="name">{{ item.name || 0 }}</p>
        </div>
      </div>
    </div>
    <div>
      <span class="title">新上线系统数</span>
      <div class="content content2">
        <div>
          <p class="tag">
            <span>{{ onLineSysNum }}</span>
          </p>
          <p class="name">近三月上线系统数</p>
        </div>
      </div>
    </div>
    <div>
      <span class="title">系统登记数及标准符合率</span>
      <div>
        <rateBar :value="rateChartData" />
      </div>
    </div>
  </div>
  <Dialog
    :title="dialogData.title"
    :visible="dialogData.visible"
    @close="dialogData.visible = false"
    :fathUrl="dialogData.fathUrl"
    :tableData="dialogData"
  />
</template>

<script setup>
import { ref, reactive, onMounted } from "vue";
import rateBar from "./charts/bar1.vue";
import Dialog from "@/components/Dialog/Dialog.vue";
import {
  GETstructuredDataStorageGroup,
  GETgetJsysxxts,
  GETgetXjxtdjsTwo,
  GETgetJyxtdjsTwo,
  GETgetJyxtbzfhlTwo,
} from "../../../api/dataSource";

let databasesNum = ref([]);
let onLineSysNum = ref(0);
const arrList = ref([]);
let rateChartData = ref({
  xData: [],
  existSysData: [],
  newSysData: [],
  sysRateData: [],
});
let dialogData = reactive({ title: "", visible: false, fathUrl: "",X:1, });
arrList.value = [
    {
      prop: "tableName",
      label: "业务处室",
      width: "80",
    },
    {
      prop: "columnName",
      label: "任务名",
      width: "80",
    },
    {
      prop: "attributeName",
      label: "系统名",
      width: "80",
    },{
      prop: "tableName",
      label: "数据库名",
      width: "80",
    },
    {
      prop: "tableName",
      label: "表名",
      width: "80",
    },
    {
      prop: "columnName",
      label: "字段名",
      width: "80",
    },{
      prop: "tableName",
      label: "源头系统名",
      width: "80",
    },
    {
      prop: "columnName",
      label: "源头数据库名",
      width: "80",
    },
    {
      prop: "errorCount",
      label: "源头字段名",
      width: "80",
    },]
function initData() {
  //数据库数量
  GETstructuredDataStorageGroup().then((res) => {
    databasesNum.value = res.data || [];
  });
  //近三月上线系统数
  GETgetJsysxxts().then((res) => {
    onLineSysNum.value = res.data[0]?.value || 0;
  });
  Promise.all([
    //新建系统登记数
    GETgetXjxtdjsTwo(),
    //既有系统登记数
    GETgetJyxtdjsTwo(),
    //既有系统标准符合率
    GETgetJyxtbzfhlTwo(),
  ]).then((res) => {
    let data = res.map((item) => item.data);
    if (data[0] && data[0].length > 0) {
      data[0].forEach((item) => {
        let key = item.name;
        rateChartData.value.xData.push(key);
        rateChartData.value.newSysData.push(item.value);
        rateChartData.value.existSysData.push(
          data[1].find((v) => v.name == key)?.value || 0
        );
        rateChartData.value.sysRateData.push(
          data[2].find((v) => v.name == key)?.value || 0
        );
      }); 
    }
  });
}

function handleDialog(data, index) {
  dialogData.visible = true;
  dialogData.title = `${data.name}数据库数量`;
  if (index == 0) {
    //数据库数量
    dialogData.fathUrl = "/zjjscApi/datasource/getSjkslMx";
    request({
    url: props.QueryConfig.url,
    method: "get",
    params: {
      pageNumber: 1,
      pageSize: 10,
    },
  }).then((res) => {
    tableData.value = res.data.records?res.data.records:res.data;
    pagetotal.value = res.data.records.length?res.data.records.length:res.data.length;
  });
  }
  if (index == 1) {
    //数据库类型
    dialogData.fathUrl = "/zjjscApi/datasource/getSjkx";
    request({
    url:  dialogData.fathUrl,
    method: "get",
    params: {
      pageNumber:1,
      pageSize: 10,
    },
  }).then((res) => {
    tableData.value = res.data.records?res.data.records:res.data;
    pagetotal.value = res.data.records.length?res.data.records.length:res.data.length;
  });
  }
  if (index == 2) {
  }
  // dialogData.fathUrl = data.fathUrl;
}

onMounted(() => {
  initData();
});
</script>

<style scoped lang="scss">
.g-container {
  height: 100%;
  display: flex;
  justify-content: space-between;

  p {
    padding: 0;
    margin: 0;
  }

  > div {
    display: flex;
    flex-direction: column;
    padding: 20px 10px 10px;
    box-sizing: border-box;
    border-radius: 4px;
    background-color: rgba(11, 44, 106, 0.6);

    &:first-child {
      width: 28%;
    }

    &:nth-child(2) {
      width: 19%;
    }

    &:nth-child(3) {
      width: 51%;
    }

    .title {
      position: relative;
      height: 26px;
      padding-left: 20px;
      font-size: 16px;
      font-weight: bold;
      color: transparent;
      background-image: linear-gradient(to bottom, #fff, #98bbff);
      -webkit-background-clip: text;
      background-clip: text;

      &:before {
        content: "";
        position: absolute;
        width: 10px;
        height: 10px;
        left: 0;
        top: 7px;
        background-color: #3a8fff;
        clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
      }
    }

    .content {
      flex: 1;
      display: flex;
      justify-content: space-between;

      > div {
        width: 33%;
        display: flex;
        flex-direction: column;
        justify-content: center;
        cursor: pointer;

        .tag {
          width: 80px;
          height: 90px;
          margin: 0 auto;
          padding-top: 1px;
          text-align: center;
          background: url("../../../static/icon1.png") no-repeat center center;
          background-size: 100% 100%;

          span {
            display: block;
            margin-top: 30px;
            font-size: 18px;
            font-weight: bold;
            color: transparent;
            background-image: linear-gradient(to bottom, #fff, #00effe);
            -webkit-background-clip: text;
            background-clip: text;
          }
        }

        .name {
          font-size: 14px;
          color: #fff;
          text-align: center;
        }
      }

      &.content2 {
        > div {
          width: 100%;
        }
      }
    }
  }
}
.scroll{
  overflow-x: auto;
  background-color: rgba(11, 44, 106, 0.6);
  &::-webkit-scrollbar {
    height: 6px;
  }
  &::-webkit-scrollbar-thumb {
    background-color: rgba(58, 143, 255, 0.5);
    border-radius: 3px;
  }
  &::-webkit-scrollbar-track {
    background-color: rgba(11, 44, 106, 0.3);
  }
}
</style>
